package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.LoginBean;
import com.renwei.yunlong.bean.OwnerUpcomingAllBean;
import com.renwei.yunlong.utils.ACache;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

import java.util.List;


/**
 * 我的待办  投诉 adapter
 *
 * Created by Administrator on 2017/9/7.
 */

public class OwnerMeUpcomingComplaintsAdapter extends RecyclerView.Adapter<OwnerMeUpcomingComplaintsAdapter.OwnerMeUpcomingComplaintsViewHolder>{

    private LayoutInflater inflater;
    private Context context;

    List<OwnerUpcomingAllBean.Rows> mList;
    ACache mCache;

    public OwnerMeUpcomingComplaintsAdapter(Context context, List<OwnerUpcomingAllBean.Rows> mList) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mList  = mList;
        mCache =  ACache.get(context);
    }

    @Override
    public OwnerMeUpcomingComplaintsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =  inflater.inflate(R.layout.item_me_upcoming_work,null);
        AutoUtils.auto(view);
        return new OwnerMeUpcomingComplaintsAdapter.OwnerMeUpcomingComplaintsViewHolder(view);
    }

    @Override
    public void onBindViewHolder(OwnerMeUpcomingComplaintsViewHolder holder, int position) {
        LoginBean loginBean = (LoginBean) mCache.getAsObject("loginBean");
        OwnerUpcomingAllBean.Rows rows = mList.get(position);

        holder.tvTitleContent.setText(rows.getContent());
        holder.tvDepartment.setText(loginBean.getRows().getCompany().getCompanyName());
        holder.tvName.setText("/"+rows.getSendUserName());

        if ("1".equals(rows.getIsOverStat())){
            holder.rlDateTime.setVisibility(View.GONE);
            holder.tvOverdue.setVisibility(View.VISIBLE);

            holder.tvOverdue.setText("逾期");
        }else {
            holder.tvOverdue.setVisibility(View.GONE);

            String DateTimeStr = rows.getSendDate();
            String [] split = DateTimeStr.split("T");

            holder.rlDateTime.setVisibility(View.VISIBLE);
            holder.tvDate.setText(split[0]);
            holder.tvTime.setText(split[1]);
        }

        if ("3".equals(rows.getKind())){
            if ("-1".equals(rows.getComplainFlag())){
                holder.button.setBackgroundResource(R.drawable.shape_red_card);
                holder.button.setText("待处理");
            }else if ("0".equals(rows.getComplainFlag())){
                holder.button.setBackgroundResource(R.drawable.shape_yellow_card);
                holder.button.setText("处理中");
            }else if ("1".equals(rows.getComplainFlag())){
                holder.button.setBackgroundResource(R.drawable.shape_yellow_card);
                holder.button.setText("处理中");
            }else if ("2".equals(rows.getComplainFlag())){
                holder.button.setBackgroundResource(R.drawable.shape_yellow_card);
                holder.button.setText("处理中");
            }else if ("3".equals(rows.getComplainFlag())){
                holder.button.setBackgroundColor(Color.parseColor("#76c56d"));
                holder.button.setText("已处理");
            }else if ("4".equals(rows.getComplainFlag())){
                holder.button.setBackgroundColor(Color.parseColor("#999691"));
                holder.button.setText("已反馈");
            }
        }
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }

    static class OwnerMeUpcomingComplaintsViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private TextView tvTitleContent;//标题内容
        private TextView tvDepartment;//部门
        private TextView tvName;//用户名
        private TextView tvDate;//日期
        private TextView tvTime;//时间
        private Button button;//状态按钮
        private RelativeLayout rlDateTime;
        private TextView tvOverdue;

        public OwnerMeUpcomingComplaintsViewHolder(View view) {
            super(view);
            itemView = view;
            tvTitleContent = (TextView) itemView.findViewById(R.id.tv_title_content);
            tvDepartment = (TextView) itemView.findViewById(R.id.tv_department);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
            button = (Button) itemView.findViewById(R.id.button);

            tvOverdue = (TextView) itemView.findViewById(R.id.tv_overdue);
            rlDateTime = (RelativeLayout) itemView.findViewById(R.id.rl_date_time);
        }
    }
}
